package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.kcl.entity.Zsk;
import vip.xiaonuo.smzq.modular.kcl.entity.param.ZskQuery;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ZskResult;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ZskXq;
import vip.xiaonuo.smzq.modular.kcl.service.IZskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 知识库
 *
 * @author sqq
 * @since 2024-04-01
 */
@Api(tags = "知识库")
@RestController
@RequestMapping("/kcl/zsk")
@Validated
public class ZskController {

    @Resource
    private IZskService iZskService;

    /**
     * 添加知识库
     */
    @ApiOperation("添加知识库")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Zsk zsk) {
        iZskService.save(zsk);
        return CommonResult.ok();
    }

    /**
     * 删除知识库
     */
    @ApiOperation("删除知识库")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid Zsk zsk) {
        iZskService.delecte(zsk.getPkid());
        return CommonResult.ok();
    }

    /**
     * 编辑知识库
     */
    @ApiOperation("编辑知识库---")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Zsk zsk) {
        iZskService.updateById(zsk);
        return CommonResult.ok();
    }

    /**
     * 知识库分页查询
     */
    @ApiOperation("知识库分页查询-数据管理")
    @GetMapping("/list")
    public CommonResult<Page<ZskXq>> page(
            @ApiParam(name = "current", value = "页数", example = "1", required = true) @RequestParam long current,
            @ApiParam(name = "size", value = "每页数量", example = "20", required = true) @RequestParam long size,
            ZskXq zsk) {
        return CommonResult.data(iZskService.page(current,size,zsk));
    }

    @ApiOperation("知识库分页查询-知识库")
    @GetMapping("/query")
    public CommonResult<Page<ZskResult>> page(
            @ApiParam(name = "current", value = "页数", example = "1", required = true) @RequestParam long current,
            @ApiParam(name = "size", value = "每页数量", example = "20", required = true) @RequestParam long size,
            ZskQuery zskQuery
    ) {
        return CommonResult.data(iZskService.page(current,size,zskQuery));
    }


    /**
     * 知识库上传
     */
    @ApiOperation("知识库上传")
    @PostMapping("/zskFileUpload")
    public CommonResult<String> zskFileUpload(
            @RequestBody @Valid ZskXq zsk

    ) {
        iZskService.zskFileUpload(zsk);
        return CommonResult.ok();
    }


    /**
     * 知识库修改
     */
    @ApiOperation("知识库修改")
    @PostMapping("/zskFileEdit")
    public CommonResult<String> zskFileEdit(
            @RequestBody @Valid ZskXq zsk
    ) {
        iZskService.zskFileEdit(zsk);
        return CommonResult.ok();
    }

    @ApiOperation("知识库文件预览")
    @GetMapping("/preview")
    public void preview(String fileId) {
        iZskService.fileShow(fileId);
    }

}
